const LINE_STYLE = {
    "Color": 1,
    /* 线型号17-0 */
    "LinStyleID": 0,
    "LinStyleID2": 17,
    "LinWidth": 0.1,
    "Xscale": 10,
    "Yscale": 10
}
/**
 *@param {array} position [ [lng,lat],[lng,lat]]
 *@param {array} attr
 *@param {object} service  {name,layerId}
 *@param {object} docName
 */
class LineString {
    static add({
        position,
        attr,
        service,
        docLayer
    }) {
        // var pointObj = [new Zondy.Object.Point2D(x, y),new Zondy.Object.Point2D(x, y)];
        var pointObj = [];
        for (let item of position) {
            pointObj.push(new Zondy.Object.Point2D(item[0], item[1]))
        }
        //构成折线的弧段
        var gArc = new Zondy.Object.Arc(pointObj);
        //构成线的折线
        var gAnyLine = new Zondy.Object.AnyLine([gArc]);
        //设置线要素的几何信息
        var gline = new Zondy.Object.GLine(gAnyLine);
        //设置要素的几何信息
        var fGeom = new Zondy.Object.FeatureGeometry({ LinGeom: [gline] });
        //设置添加线要素的图形参数信息
        var clineInfo = new Zondy.Object.CLineInfo(LINE_STYLE);
        //设置要素的图形参数信息
        var graphicInfo = new Zondy.Object.WebGraphicsInfo({
            InfoType: 2, LinInfo: clineInfo
        });

        //设置添加线要素的属性信息
        var attValue = attr;
        /* 2、要素集 */
        var newFeature = new Zondy.Object.Feature({ fGeom: fGeom, GraphicInfo: graphicInfo, AttValue: attValue });
        //设置要素为线要素
        newFeature.setFType(2);

        //创建一个要素数据集
        var featureSet = new Zondy.Object.FeatureSet();
        var fldNumber = attr.length; //属性个数
        var fldName = [];
        var fldType = [];
        //创建属性结构设置对象
        var cAttStruct = new Zondy.Object.CAttStruct({
            FldName: fldName,
            FldNumber: fldNumber,
            FldType: fldType
        });
        //设置要素数据集的树形结构
        featureSet.AttStruct = cAttStruct;
        //将添加的线要素添加到属性数据集中
        featureSet.addFeature(newFeature);
        /* 3、调用服务 */
        var editDocFeature = new Zondy.Service.EditDocFeature(service.name, service.layerId, {
            // ip: "localhost",
            // port: "6163"   
        });
        editDocFeature.add(featureSet, this.onLineSuccess(docLayer));
    }
    static onLineSuccess(docLayer) {
        return function (result) {
            if (result) {
                alert("添加线要素成功！");
                docLayer.refresh();
            } else {
                alert("添加线要素失败！");
            }
        }
    }
}